
<img id="calenderpreload" src="<?php echo Yii::app()->baseUrl; ?>/images/s_preloader.gif" style="position: fixed;top:50%; right: 50%;z-index: 1000;"/>
<script type="text/javascript">
    function showCalender(onselect, config, context) {


        var calendar = $('#calendar').fullCalendar({
        header: {
        left: 'prev,next today',
                center: 'title'
        },
                defaultView: config.defaultView,
                minTime: config.minTime,
                maxTime: config.maxTime,
                slotMinutes: config.slotMinutes,
                selectable: config.selectable,
                selectHelper: true,
                defaultEventMinutes: 30,
                slotEventOverlap: false,
                hiddenDays:config.hiddenDays,
                eventClick:config.eventClick,
                slotEventOverlap:false,
                select: function(start, end, allDay) {
                    if (start.getTime() > new Date().getTime())
                    {
                        onselect(start, context)
                    } else {
                        alert('Time already passed ');
                    }

                },
                editable: config.editable,
            events: function(start, end, callback) {
                 $("#calenderpreload").show();
            $.ajax({
                url: <?php echo "'" . Yii::app()->createUrl('booking/getEvents') . "'"; ?>,
                dataType: 'json',
                data: {
                    start: start.getFullYear() + '-' + parseInt(start.getMonth() + 1) + '-' + start.getDate(),
                    end: Math.round(end.getTime() / 1000),
                    resource: context['resource_id'],
                },
                success: function(result) {
                    var events = [];
                    for (var i = 0; i < result.length; ++i)
                    {
                        events.push({
                            id: result[i].id,
                            start: result[i].start,
                            title: result[i].title,
                            end: result[i].end,
                            allDay: result[i].allDay,
                            backgroundColor: result[i].backgroundColor,
                            borderColor: result[i].borderColor
                        });
                    }

                    callback(events);
                },
                complete:function (){
                     $("#calenderpreload").hide();
                }
            });
            }
        });
    }
    ;

</script>


